package com.nursing.Dao;

import com.nursing.bean.CareTask;
import com.nursing.model.dto.CareTaskDto;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CareTaskDao {
    @Select("SELECT ct.*, n.name nurseName FROM care_task ct LEFT JOIN nurse n ON ct.nurse_id = n.id")
    List<CareTaskDto> getAll();

    @Select("SELECT * FROM care_task WHERE id = #{id}")
    CareTask getById(Integer id);

    @Select("SELECT * FROM care_task WHERE plan_id = #{planId}")
    List<CareTask> getByPlanId(Integer planId);

    @Insert("INSERT INTO care_task (plan_id, nurse_id, task_details, status) " +
            "VALUES (#{planId}, #{nurseId}, #{taskDetails}, #{status})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(CareTask careTask);

    @Update("UPDATE care_task SET task_details = #{taskDetails}, status = #{status}, executed_at = #{executedAt} WHERE id = #{id}")
    void update(CareTask careTask);


    @Delete("DELETE FROM care_task WHERE id = #{id}")
    void delete(Integer id);
}